#pragma once

#include "noncopyable.h"
#include <unistd.h>

class InetAddress;

// 封装socket fd
class Socket : noncopyable
{
public:
    explicit Socket(const int sock_fd): sockfd_(sock_fd){}

    ~Socket(){ close(sockfd_);}

    int fd() const { return sockfd_; }
    void bindAddress(const InetAddress &localaddr);
    void listen() const;
    int accept(InetAddress *peer_addr);

    void shutdownWrite() const;

    void setTcpNoDelay(bool on) const;
    void setReuseAddr(bool on) const;
    void setReusePort(bool on) const;
    void setKeepAlive(bool on) const;

private:
    const int sockfd_;
};